import * as echarts from "echarts";

const screen_w = window.innerWidth;

const font_size = screen_w > 2000 ? 25 : 16

// 柱形图的宽度
let item_bar_w = screen_w > 2000 ? 20 : 16
// 仿真数据格式用于使用者确认格式用的
export const _ec_data_format = {
	series: [
		{
			name: "",
			value: "",
			color: "",
		}
	]
};

/**
 * @description: 生成ec图表配置信息
 * @author: 王琛
 * @Date: 2022-11-25 15:29:43
 * @param {*}
 * @return {*}
 */
export function getOptions({series} = {}) {
	if (!series.length) series = _ec_data_format;
	// y轴分类种类
	let yaxisData = [];
	// x轴的数据
	let xaxisData = [];
	// 色值配备
	let seriesColroList = [];
	
	for (let i = 0, len = series.length; i < len; i++) {
		const series_item = series[i];
		yaxisData.push(series_item.name)
		xaxisData.push(series_item.value)
		seriesColroList.push(series_item.color)
	}
	

	// 主配置文件
	let options = {
		tooltip: {
			textStyle:{
				fontSize:font_size
			}
		},
		grid: {
			left: "0%",
			right: 30,
			top: "0%",
			bottom: "0%",
			containLabel: true,
		},
		xAxis: [
			{
				type: "value",
				axisLabel: {
					interval: 0,
					color: "#fff",
					fontSize: font_size,
				},
				axisLine: {
					lineStyle: {
						//y轴网格线设置
						color: "rgba(0, 168, 255, 0.4)",
						width: 1,
					},
				},
				splitLine: {
					lineStyle: {
						type: "dashed",
						opacity: 0.4
					}
				},
				axisTick: {
					show: false,
				},
			},
		],
		yAxis: [
			{
				type: "category",
				name: "",
				nameTextStyle: {
					color: "#fff",
					fontWeight: 400,
					fontSize: font_size,
				},
				axisTick: {
					show: true,
					length: 5,
					lineStyle: {
						color: "#fff"
					}
				},
				axisLine: {
					show: true,
					lineStyle: {
						color: "#fff",
						width: 1,
					},
				},
				splitLine: {
					show: false,
				},
				axisLabel: {
					show: true,
					fontSize: font_size,
					color: "#fff",
				},
				data: yaxisData
			},
		],
		series: [
			{
				type: "bar",
				barWidth: item_bar_w,
				label: {
					show: true,
					position: "right",
					color: "#fff",
					fontSize: font_size
				},
				itemStyle: {
					borderRadius: [item_bar_w / 2, item_bar_w / 2, item_bar_w / 2, item_bar_w / 2],
					color: (parameter) => {
						return new echarts.graphic.LinearGradient(1, 0, 0, 0, [
							{
								offset: 0,
								color: `rgba(${seriesColroList[parameter["dataIndex"]] || "255, 0, 0"}, 1)`,
							},
							{
								offset: 0.5,
								color: `rgba(${seriesColroList[parameter["dataIndex"]] || "255, 0, 0"}, 1)`,
							},
							{
								offset: 1,
								color: `rgba(${seriesColroList[parameter["dataIndex"]] || "255, 0, 0"}, 0)`,
							},
						])
					}
				},
				data: xaxisData,
			},
		],
	};
	return options;
}

/**
 * @description: 有些表图数据需要通过js处理得到,结合实际业务来确定师傅哦哦使用次函数,如不适用可以删除掉
 * @author: 王琛
 * @Date: 2023-03-09 14:53:48
 * @param {*}
 * @return {*}
 */
export function getSeries({} = {}) {
	let _series = {};
	return _series;
}





